import pandas as pd
from xbase_util.dangerous_util import get_splunk_pa, get_splunk_waf


def get_all_threats(base_config, end_time, start_time):
    threat_pa = pd.DataFrame(get_splunk_pa(start_time=start_time, end_time=end_time,
                                           splunk_host=base_config['splunk']['host'],
                                           splunk_port=base_config['splunk']['port'],
                                           splunk_scheme=base_config['splunk']['scheme'],
                                           splunk_username=base_config['splunk']['username'],
                                           splunk_password=base_config['splunk']['password'],
                                           splunk_filter=base_config['splunk']['splunk_filter'],
                                           ))
    print(f"异常数量pa:{len(threat_pa)}")
    threat_pa['type'] = 'ids'
    threat_waf = pd.DataFrame(get_splunk_waf(start_time=start_time, end_time=end_time,
                                             splunk_host=base_config['splunk']['host'],
                                             splunk_port=base_config['splunk']['port'],
                                             splunk_scheme=base_config['splunk']['scheme'],
                                             splunk_username=base_config['splunk']['username'],
                                             splunk_password=base_config['splunk']['password']
                                             ))
    threat_waf['type'] = 'waf'
    print(f"异常数量waf:{len(threat_waf)}")
    dangerous_all = pd.concat([threat_pa, threat_waf])
    return dangerous_all



def split_data_by_chunk(data, chunk_size=1000):
    """
    将数据分割成每个包含 `chunk_size` 个元素的多个列表。

    :param data: 输入的原始数据，可以是列表或任何可迭代对象
    :param chunk_size: 每个子列表包含的数据量，默认是 1000
    :return: 一个包含若干子列表的列表，每个子列表包含最多 `chunk_size` 个元素
    """
    return [data[i:i + chunk_size] for i in range(0, len(data), chunk_size)]